<?php //today.php?city=shenzhen&cats=play
/*
Coder: NetPuter
Description: 今日团购聚合
*/
include("func.php");

// 以 HTML 方式查看 RSS Feed
function feedviewer($city, $cats = "all") {
	$rss = "feed/{$city}_{$cats}.rss";

	if (file_exists(ABSPATH.$rss)) {
		$file = "";
		$f = fopen(ABSPATH.$rss,"r");
		while (!feof($f)) {
		    $file .= fgets($f,4096);
		}
		fclose($f);

		$parser = xml_parser_create();
		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
		xml_parse_into_struct($parser, $file, $items);
		xml_parser_free($parser);

		foreach ($items as $item) {
		    $tag  = strtolower($item["tag"]);
		    $type = strtolower($item["type"]);
			if ($tag == "item" && $type == "open") {
				$level = $item["level"] + 1;
			}
			
			if (isset($level)) {
				if  ($item["level"] == $level && $tag == "description") {
					$content = $item["value"];
				}
			}
		}

		return $content;
	} else {
		return false;
	}
}

$catsArr = array("all", "eat", "play", "beauty", "sports", "person", "other");

if (isset($_GET["city"])) {
	$city = $_GET["city"];
	if (isset($_GET["cats"])) {
		$cats = in_array(strtolower($_GET["cats"]), $catsArr) ? $_GET["cats"] : "all";
	} else {
		$cats = "all";
	}
	
	$today = feedviewer($city, $cats);
	if ($today) {
		echo $today;
	} else {
		echo "暂无相关内容";
	}	
} else {
	// 转至 subscribe.php
}

echo get_header("今日团购聚合");
echo get_footer();
?>